#/bin/bash
echo 正在安装，请稍等...
echo 正在生成服务文件

#*****************************************************************************************************************************
#execute_name 和 service_name 需要人工输入
#*****************************************************************************************************************************
execute_name="java -Xms1024m -Xmx1024m -XX:+UseG1GC -XX:+PrintGCDetails -jar /home/yt/workspace/YuTo.jar >/dev/null 2>&1 &"
#execute_name=${PWD}/test
service_name=yt_fd2_webserver
#******************************************************************************************************************************

#echo ${execute_name}
execute_sh=${PWD}/${service_name}_start.sh
service_file=${service_name}.service

echo "#!/bin/bash" > ${execute_sh}
echo "${execute_name}" >> ${execute_sh}
chmod +x ${execute_sh}

echo "[Unit]" > ${service_file}
echo "Description=This is ${service_file}" >> ${service_file}
echo "[Service]" >> ${service_file}
echo "Type=simple" >> ${service_file}
echo "ExecStart="${execute_sh}" start" >> ${service_file}
echo "Restart=on-failure" >> ${service_file}
echo "[Install]" >> ${service_file}
echo "WantedBy=multi-user.target" >> ${service_file}


echo 正在安装服务
cp ${service_file} /etc/systemd/system/${service_file}

systemctl daemon-reload 
systemctl enable ${service_file}
service ${service_name} restart

echo 安装完成
